<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Site/classes/PhpFox_ComponentStyleSelector.class.php, $Author:  $ */



/** Component for selecting user style
 * @version $Id: PhpFox_ComponentStyleSelector.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.site
 *   
 */
class PhpFox_Mod_Site_ComponentStyleSelector extends BaseComponent
{
    function process()
    {
        // $oCssItem = &$this->_oModule->getItem('Css');
        /* @var $oCssItem PhpFox_Mod_Site_ItemCss */
        $oStyleService = &$this->_oModule->getService('Style');
        /* @var $oStyleService PhpFox_Mod_Site_ServiceStyle */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oReq = &App::getRequest();
        $oTpl = &$this->_oModule->getTemplate();

        if (App::getSetting('site_themes'))
        {
            return '';
        }
        if ($iStyleId = $oReq->getInt('css'))
        {
            // if ($oCssItem->load($iStyleId))
            // {
                $oCurrUser = $oSecurityService->getCurrentUser();
                $oCurrUser->aData['css'] = $iStyleId;
                $oCurrUser->update(array('css'));
                App::plugin_changeTheme($oCurrUser);
        		
                $aRow = $this->oDatabase->getRow("SELECT c.name, c.file, l.file as cssLayout ".
                	" FROM ". App::getT('css') ." AS c ".
                	" ,". App::getT('html_layout') ." AS l ".
                	" WHERE c.id = '". $iStyleId ."' AND c.html = l.id");
           		setcookie("cssName",$aRow['name'],"0","/");
				setcookie("cssFile",$aRow['file'],"0","/");          
				setcookie("cssLayout",$aRow['cssLayout'],"0","/"); 				
           // }
            App::gotoUrl('public.account');
        }
        list($sStyleFile, $sStyleName) = $oStyleService->getUserStyle();
        $aItems = $oStyleService->getListOfThemes();
        $aStyles = array();
        foreach ($aItems as $aItem)
        {
            $aStyles[$aItem['id']] = $aItem['name'];
        }
        $oTpl->assign(array(
            'sCurrentTheme' => $sStyleName,
            'aStyles'       => $aStyles,
        ));
        return $oTpl->fetch('StyleSelector.html');
    }
}
?>